package com.ysyx.ysyx_passengerconfirmo.config;

import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Component;

import javax.annotation.Resources;
import java.util.concurrent.TimeUnit;

/**
 * Created by IntelliJ IDEA.
 *
 * @description: xxxx接口/类
 * @author:郭宇轩
 * @create:2023/4/12 11:07
 */
@Component
public class RedisKeyExpiredListener extends KeyExpirationEventMessageListener {

    @Autowired
    private RedissonClient redissonClient;
    public RedisKeyExpiredListener(RedisMessageListenerContainer listenerContainer) {
        super(listenerContainer);
    }

    @Override
    public void onMessage(Message message, byte[] pattern) {
        super.onMessage(message, pattern);
        System.out.println("过期的key:"+message.toString());
        String key = message.toString();
        redissonClient.getMap(key).expire(30, TimeUnit.SECONDS);
        if (key.split(":")[0].equals("orderinfo")){
            String orderId = key.split(":")[1];
        }


    }
}
